Exchange the first and last charsΒΆ

Change a given string to a new string where the first
and last chars have been exchanged.
def change_sring(S):
    return S[-1:] + S[1:-1] + S[:1]

# test
print(change_sring('abcd'))            # dbca
print(change_sring('12345'))           # 52341